//
//  LoiNhacViewController.m
//  NhomTuan
//
//  Created by Buffalo on 1/30/15.
//  Copyright (c) 2015 Buffalo. All rights reserved.
//

#import "LoiNhacViewController.h"
@interface LoiNhacViewController ()

@end

@implementation LoiNhacViewController
//bool like;
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    self.lblSongCode.text = self.song.code;
    self.lblSongName.text = self.song.name.uppercaseString;
    self.textSongLyrics.text = self.song.lyrics;
    self.singer = [[Singer alloc] initSingerWithId:self.song.singerId];
    self.lblSingerName.text = self.singer.name.uppercaseString;
    [self setLikeImage];
}

- (UIStatusBarStyle)preferredStatusBarStyle {
    return UIStatusBarStyleLightContent;
}
- (void)viewWillAppear:(BOOL)animated {
    self.automaticallyAdjustsScrollViewInsets = NO;
    [self.navigationController.navigationBar setBarTintColor:[AppUtils greenColor]];
    [self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];
    UIImage *image = [UIImage imageNamed:@"img_logo.png"];
    UIImageView *titleImg = [[UIImageView alloc] initWithImage:image];
    [self.navigationController.navigationBar.topItem setTitleView:titleImg];
}
- (IBAction)btnLike:(UIBarButtonItem *)sender {
    if (self.song.like) {
        NSString *message = [NSString stringWithFormat:@"Bạn có đồng ý bỏ thích bài hát: \n'%@' ?", self.song.name];
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Bỏ thích bài hát?"
                                                        message:message
                                                       delegate:self
                                              cancelButtonTitle:@"Hủy"
                                              otherButtonTitles:@"Đồng ý", nil];
        alert.tag = 100;
        [alert show];
    } else {
        [[AppManager defaultmanager].favorSongList addObject:self.song.code];
        self.song.like = !self.song.like;
        [self setLikeImage];
        [AppManager save];
    }
}

- (void)setLikeImage {
    self.btnLike.image = self.song.like == true ? [UIImage imageNamed:@"icon_navigation_bar_already_like.png"] : [UIImage imageNamed:@"icon_navigation_bar_not_like.png"];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    if (alertView.tag == 100) {
        if (buttonIndex == 1) {
            [[AppManager defaultmanager].favorSongList removeObject:self.song.code];
            self.song.like = !self.song.like;
            [self setLikeImage];
            [AppManager save];
        }
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
